<!DOCTYPE html>
<html lang="zh-Hans">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="Bingo" />



<meta name="description" content="stl2的作业">
<meta property="og:type" content="article">
<meta property="og:title" content="coursera_STL2作业">
<meta property="og:url" content="http://blog.acbingo.cn/2016/01/24/coursera_STL2作业/index.html">
<meta property="og:site_name" content="Bingo's Blog">
<meta property="og:description" content="stl2的作业">
<meta property="og:updated_time" content="2016-01-23T17:29:38.164Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="coursera_STL2作业">
<meta name="twitter:description" content="stl2的作业">

<link rel="apple-touch-icon" href= "/apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="Bingo&#39;s Blog" type="application/atom+xml">



    <link rel="shortcut icon" href="/favicon.png">





    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>coursera_STL2作业 | Bingo&#39;s Blog</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: false,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: true
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = "\/";</script>






</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">Bingo</a></h1>
        </hgroup>

        
        <p class="header-subtitle">Here&#39;s My Second Brains</p>
        

        
            <form id="search-form">
            <input type="text" id="local-search-input" name="q" placeholder="search..." class="search form-control" autocomplete="off" autocorrect="off" searchonload="false" />
            <i class="fa fa-times" onclick="resetSearch()"></i>
            </form>
            <div id="local-search-result"></div>
            <p class='no-result'>No results found <i class='fa fa-spinner fa-pulse'></i></p>
        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                            <li><a href="/tags/">标签云</a></li>
                        
                            <li><a href="http://acbingo.cn/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="/&#116;&#x66;&#117;&#116;&#121;&#x40;&#x71;&#113;&#46;&#99;&#111;&#109;" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/ACBingo" title="GitHub"></a>
                            
                                <a class="fa 知乎" href="https://www.zhihu.com/people/li-bing-59-10" title="知乎"></a>
                            
                                <a class="fa StackOverflow" href="http://stackoverflow.com/users/6059386/acbingo" title="StackOverflow"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Android/">Android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Array/">Array</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hash-Table/">Hash Table</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/KMP/">KMP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LeetCode/">LeetCode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linked-List/">Linked List</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Math/">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/STL/">STL</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/String/">String</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/anroid/">anroid</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/books/">books</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c#</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocos/">cocos</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cocos2dx/">cocos2dx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/const/">const</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/coursera/">coursera</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/github/">github</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hash/">hash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hdu/">hdu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/markdown/">markdown</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/offer/">offer</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/other/">other</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/poj/">poj</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shadowsocks/">shadowsocks</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/string/">string</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ubuntu/">ubuntu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/uva/">uva</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/二分/">二分</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/二叉树/">二叉树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/位运算/">位运算</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/其它/">其它</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/分治/">分治</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/动态规划/">动态规划</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/单调队列/">单调队列</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/回溯/">回溯</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/字符串/">字符串</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/字符串匹配/">字符串匹配</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/指针/">指针</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/排序/">排序</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/操作系统/">操作系统</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/枚举/">枚举</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/树/">树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/算法/">算法</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/红黑树/">红黑树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线段树/">线段树</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/继承/">继承</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/编译原理/">编译原理</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/虚函数/">虚函数</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/逆序对/">逆序对</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/递归/">递归</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/链表/">链表</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于前端</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">Bingo</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">Bingo</a></h1>
            </hgroup>
            
            <p class="header-subtitle">Here&#39;s My Second Brains</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                    <li><a href="/tags/">标签云</a></li>
                
                    <li><a href="http://acbingo.cn/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="/&#116;&#x66;&#117;&#116;&#121;&#x40;&#x71;&#113;&#46;&#99;&#111;&#109;" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/ACBingo" title="GitHub"></a>
                            
                                <a class="fa 知乎" target="_blank" href="https://www.zhihu.com/people/li-bing-59-10" title="知乎"></a>
                            
                                <a class="fa StackOverflow" target="_blank" href="http://stackoverflow.com/users/6059386/acbingo" title="StackOverflow"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap"><article id="post-coursera_STL2作业" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/01/24/coursera_STL2作业/" class="article-date">
      <time datetime="2016-01-23T17:19:19.000Z" itemprop="datePublished">2016-01-24</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      coursera_STL2作业
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/coursera/">coursera</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p>stl2的作业<br><a id="more"></a></p>
<h1 id="编程题＃1"><a href="#编程题＃1" class="headerlink" title="编程题＃1"></a>编程题＃1</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 1000ms 内存限制: 65536kB</p>
<p>描述</p>
<p>下面的程序用枚举法解决如下问题，请填空。</p>
<p>平面上的一个矩形，如果其边平行于坐标轴，我们就称其为“标准矩形”。给定不重复的 n 个整点（横、纵坐标都是整数的点），求从这n个点中任取4点作为顶点所构成的四边形中，有多少个是标准矩形。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;vector&gt;</div><div class="line">#include &lt;algorithm&gt;</div><div class="line">using namespace std;</div><div class="line">struct Point &#123;</div><div class="line">    int x;</div><div class="line">    int y;</div><div class="line">    Point(int x_,int y_):x(x_),y(y_) &#123; &#125;</div><div class="line">&#125;;</div><div class="line">bool operator &lt; ( const Point &amp; p1, const Point &amp; p2)</div><div class="line">&#123;</div><div class="line">    if( p1.y &lt; p2.y )</div><div class="line">        return true;</div><div class="line">    else if( p1.y == p2.y )</div><div class="line">        return p1.x &lt; p2.x;</div><div class="line">    else</div><div class="line">        return false;</div><div class="line">&#125;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">    int t;</div><div class="line">    int x,y;</div><div class="line">    cin &gt;&gt; t;</div><div class="line">    vector&lt;Point&gt; v;</div><div class="line">    while( t -- ) &#123;</div><div class="line">        cin &gt;&gt; x &gt;&gt; y;</div><div class="line">        v.push_back(Point(x,y));</div><div class="line">    &#125;</div><div class="line">    vector&lt;Point&gt;::iterator i,j;</div><div class="line">    int nTotalNum = 0;</div><div class="line">// 在此处补充你的代码</div><div class="line">return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>输入</p>
<p>第一行是点的数目</p>
<p>其后每一行都代表一个点，由两个整数表示，第一个是x坐标，第二个是y坐标</p>
<p>输出</p>
<p>输出标准矩形的数目</p>
<p>样例输入</p>
<p>6<br>2 3<br>2 5<br>4 5<br>4 4<br>2 4<br>4 3<br>样例输出</p>
<p>3<br>提示</p>
<p>所缺代码具有如下形式：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">_____________________;</div><div class="line">for( i = v.begin(); i &lt; v.end() - 1;i ++ )</div><div class="line">    for(_____________; ______________; _____________) &#123;</div><div class="line">        if(binary_search(v.begin(),v.end(),Point( j-&gt;x, i-&gt;y)) &amp;&amp;</div><div class="line">            ____________________________________________ &amp;&amp;</div><div class="line">            ____________________________________________ &amp;&amp;</div><div class="line">            ____________________________________________ )</div><div class="line">            nTotalNum ++;</div><div class="line">    &#125;</div><div class="line">cout &lt;&lt; _________________;</div></pre></td></tr></table></figure></p>
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><p>思路：<br>其实，点的关系只要满足存在这四个点就可以了(x1,y1)(x2,y2)(x1,y2)(x2,y1)。注意x1!=x2,x2!=x1<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">sort(v.begin(), v.end());</div><div class="line">	for (i = v.begin(); i &lt; v.end() - 1; i++)</div><div class="line">		for (j = i+1; j &lt; v.end(); j++)</div><div class="line">		&#123;</div><div class="line">			if (binary_search(v.begin(), v.end(), Point(j-&gt;x, i-&gt;y)) &amp;&amp;</div><div class="line">				binary_search(v.begin(), v.end(), Point(i-&gt;x, j-&gt;y)) &amp;&amp;</div><div class="line">				(i-&gt;x!=j-&gt;x) &amp;&amp;</div><div class="line">				(i-&gt;y!=j-&gt;y))</div><div class="line">					nTotalNum++;</div><div class="line">		&#125;</div><div class="line">	cout &lt;&lt; nTotalNum/2 &lt;&lt; endl;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃2"><a href="#编程题＃2" class="headerlink" title="编程题＃2"></a>编程题＃2</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 1000ms 内存限制: 65536kB</p>
<p>描述</p>
<p>写一个自己的 CMyistream_iterator 模板，使之能和 istream_iterator 模板达到一样的效果，即：</p>
<p>输入：</p>
<p>79 90 20 hello me</p>
<p>输出：</p>
<p>79</p>
<p>79,90,20</p>
<p>hello,me<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">using namespace std;</div><div class="line">// 在此处补充你的代码</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">    CMyistream_iterator&lt;int&gt; inputInt(cin);</div><div class="line">    int n1,n2,n3;</div><div class="line">    n1 = * inputInt; //读入 n1</div><div class="line">    int tmp = * inputInt;</div><div class="line">    cout &lt;&lt; tmp &lt;&lt; endl;</div><div class="line">    inputInt ++;</div><div class="line">    n2 = * inputInt; //读入 n2</div><div class="line">    inputInt ++;</div><div class="line">    n3 = * inputInt; //读入 n3</div><div class="line">    cout &lt;&lt; n1 &lt;&lt; &quot;,&quot; &lt;&lt; n2&lt;&lt; &quot;,&quot; &lt;&lt; n3 &lt;&lt; endl;</div><div class="line">    CMyistream_iterator&lt;string&gt; inputStr(cin);</div><div class="line">    string s1,s2;</div><div class="line">    s1 = * inputStr;</div><div class="line">    inputStr ++;</div><div class="line">    s2 = * inputStr;</div><div class="line">    cout &lt;&lt; s1 &lt;&lt; &quot;,&quot; &lt;&lt; s2 &lt;&lt; endl;</div><div class="line">    return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>输入</p>
<p>79 90 20 hello me</p>
<p>输出</p>
<p>79</p>
<p>79,90,20</p>
<p>hello,me</p>
<p>样例输入</p>
<p>79 90 20 hello me<br>样例输出</p>
<p>79<br>79,90,20<br>hello,me<br>提示<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">istream_iterator模版使用说明：</div><div class="line"></div><div class="line">其构造函数执行过程中就会要求输入，然后每次执行++，则读取输入流中的下一个项目，执行 * 则返回上次从输入流中读取的项目。例如，下面程序运行时，就会等待用户输入数据，输入数据后程序才会结束：</div><div class="line"></div><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line">using namespace std;</div><div class="line">int main() &#123;</div><div class="line">        istream_iterator&lt;int&gt; inputInt(cin);</div><div class="line">        return 0;</div><div class="line">&#125;</div><div class="line">下面程序运行时，如果输入 12 34 程序输出结果是： 12,12</div><div class="line"></div><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line">using namespace std;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">        istream_iterator&lt;int&gt; inputInt(cin);</div><div class="line">        cout &lt;&lt; * inputInt &lt;&lt; &quot;,&quot; &lt;&lt; * inputInt &lt;&lt; endl;</div><div class="line">        return 0;</div><div class="line">&#125;</div><div class="line">下面程序运行时，如果输入 12 34 56程序输出结果是： 12,56</div><div class="line"></div><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line">using namespace std;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">        istream_iterator&lt;int&gt; inputInt(cin);</div><div class="line">        cout &lt;&lt; * inputInt &lt;&lt; &quot;,&quot; ;</div><div class="line">        inputInt ++;</div><div class="line">        inputInt ++;</div><div class="line">        cout &lt;&lt; * inputInt;</div><div class="line">        return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h2 id="代码-1"><a href="#代码-1" class="headerlink" title="代码"></a>代码</h2><p>没啥可说的。仔细听课了就会。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">template &lt;class T&gt;</div><div class="line">class CMyistream_iterator</div><div class="line">&#123;</div><div class="line">public:</div><div class="line">	CMyistream_iterator(istream &amp;input) :in(input) &#123;</div><div class="line">		in &gt;&gt; a;</div><div class="line">	&#125;</div><div class="line">	T operator *() &#123;</div><div class="line">		return a;</div><div class="line">	&#125;</div><div class="line">	void operator ++(int) &#123;</div><div class="line">		in &gt;&gt; a;</div><div class="line">	&#125;</div><div class="line">private:</div><div class="line">	T a;</div><div class="line">	istream &amp; in;</div><div class="line">&#125;;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃3：Set"><a href="#编程题＃3：Set" class="headerlink" title="编程题＃3：Set"></a>编程题＃3：Set</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 5000ms 内存限制: 100000kB</p>
<p>描述</p>
<p>现有一整数集（允许有重复元素），初始为空。我们定义如下操作：</p>
<p>add x 把x加入集合</p>
<p>del x 把集合中所有与x相等的元素删除</p>
<p>ask x 对集合中元素x的情况询问</p>
<p>对每种操作，我们要求进行如下输出。</p>
<p>add 输出操作后集合中x的个数</p>
<p>del 输出操作前集合中x的个数</p>
<p>ask 先输出0或1表示x是否曾被加入集合（0表示不曾加入），再输出当前集合中x的个数，中间用空格格开。</p>
<p>输入</p>
<p>第一行是一个整数n，表示命令数。0&lt;=n&lt;=100000。</p>
<p>后面n行命令，如Description中所述。</p>
<p>输出</p>
<p>共n行，每行按要求输出。</p>
<p>样例输入</p>
<p>7<br>add 1<br>add 1<br>ask 1<br>ask 2<br>del 2<br>del 1<br>ask 1<br>样例输出</p>
<p>1<br>2<br>1 2<br>0 0<br>0<br>2<br>1 0<br>提示</p>
<p>Please use STL’s set and multiset to finish the task</p>
<h2 id="代码-2"><a href="#代码-2" class="headerlink" title="代码"></a>代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;set&gt;</div><div class="line">#include &lt;string&gt;</div><div class="line">#include &lt;iterator&gt;</div><div class="line"></div><div class="line">using namespace std;</div><div class="line"></div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">	multiset&lt;int&gt; mset;</div><div class="line">	set&lt;int&gt; mm;</div><div class="line">	char commend[5];</div><div class="line">	int i, n, num;</div><div class="line">	cin &gt;&gt; n;</div><div class="line">	for (i = 0; i&lt;n; i++)</div><div class="line">	&#123;</div><div class="line">		cin &gt;&gt; commend &gt;&gt; num;</div><div class="line">		switch (commend[1])</div><div class="line">		&#123;</div><div class="line">		case &apos;d&apos;:</div><div class="line">			mset.insert(num);</div><div class="line">			mm.insert(num);</div><div class="line">			cout &lt;&lt; mset.count(num) &lt;&lt; endl;</div><div class="line">			break;</div><div class="line">		case &apos;e&apos;:</div><div class="line">			cout &lt;&lt; mset.count(num) &lt;&lt; endl;</div><div class="line">			mset.erase(num);</div><div class="line">			break;</div><div class="line">		case &apos;s&apos;:</div><div class="line">			if (mm.find(num) == mm.end())</div><div class="line">				cout &lt;&lt; &quot;0 0&quot; &lt;&lt; endl;</div><div class="line">			else</div><div class="line">			&#123;</div><div class="line">				cout &lt;&lt; &quot;1 &quot;;</div><div class="line">				cout &lt;&lt; mset.count(num) &lt;&lt; endl;</div><div class="line">			&#125;</div><div class="line">			break;</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">	return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h1 id="编程题＃4：-字符串操作"><a href="#编程题＃4：-字符串操作" class="headerlink" title="编程题＃4： 字符串操作"></a>编程题＃4： 字符串操作</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 1000ms 内存限制: 65536kB</p>
<p>描述</p>
<p>给定n个字符串（从1开始编号），每个字符串中的字符位置从0开始编号，长度为1-500，现有如下若干操作：</p>
<p>copy N X L：取出第N个字符串第X个字符开始的长度为L的字符串。</p>
<p>add S1 S2：判断S1，S2是否为0-99999之间的整数，若是则将其转化为整数做加法，若不是，则作字符串加法，返回的值为一字符串。</p>
<p>find S N：在第N个字符串中从左开始找寻S字符串，返回其第一次出现的位置，若没有找到，返回字符串的长度。</p>
<p>rfind S N：在第N个字符串中从右开始找寻S字符串，返回其第一次出现的位置，若没有找到，返回字符串的长度。</p>
<p>insert S N X：在第N个字符串的第X个字符位置中插入S字符串。</p>
<p>reset S N：将第N个字符串变为S。</p>
<p>print N：打印输出第N个字符串。</p>
<p>printall：打印输出所有字符串。</p>
<p>over：结束操作。</p>
<p>其中N，X，L可由find与rfind操作表达式构成，S，S1，S2可由copy与add操作表达式构成。</p>
<p>输入</p>
<p>第一行为一个整数n（n在1-20之间）</p>
<p>接下来n行为n个字符串，字符串不包含空格及操作命令等。</p>
<p>接下来若干行为一系列操作，直到over结束。</p>
<p>输出</p>
<p>根据操作提示输出对应字符串。</p>
<p>样例输入</p>
<p>3<br>329strjvc<br>Opadfk48<br>Ifjoqwoqejr<br>insert copy 1 find 2 1 2 2 2<br>print 2<br>reset add copy 1 find 3 1 3 copy 2 find 2 2 2 3<br>print 3<br>insert a 3 2<br>printall<br>over<br>样例输出</p>
<p>Op29adfk48<br>358<br>329strjvc<br>Op29adfk48<br>35a8<br>提示</p>
<p>推荐使用string类中的相关操作函数。</p>
<h1 id="编程题＃5：-热血格斗场"><a href="#编程题＃5：-热血格斗场" class="headerlink" title="编程题＃5： 热血格斗场"></a>编程题＃5： 热血格斗场</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 1000ms 内存限制: 65536kB</p>
<p>描述</p>
<p>为了迎接08年的奥运会，让大家更加了解各种格斗运动，facer新开了一家热血格斗场。格斗场实行会员制，但是新来的会员不需要交入会费，而只要同一名老会员打一场表演赛，证明自己的实力。</p>
<p>我们假设格斗的实力可以用一个正整数表示，成为实力值。另外，每个人都有一个唯一的id，也是一个正整数。为了使得比赛更好看，每一个新队员都会选择与他实力最为接近的人比赛，即比赛双方的实力值之差的绝对值越小越好，如果有两个人的实力值与他差别相同，则他会选择比他弱的那个（显然，虐人必被虐好）。</p>
<p>不幸的是，Facer一不小心把比赛记录弄丢了，但是他还保留着会员的注册记录。现在请你帮facer恢复比赛纪录，按照时间顺序依次输出每场比赛双方的id。</p>
<p>输入</p>
<p>第一行一个数n(0 &lt; n &lt;=100000)，表示格斗场新来的会员数（不包括facer）。以后n行每一行两个数，按照入会的时间给出会员的id和实力值。一开始，facer就算是会员，id为1，实力值1000000000。输入保证两人的实力值不同。</p>
<p>输出</p>
<p>N行，每行两个数，为每场比赛双方的id，新手的id写在前面。</p>
<p>样例输入</p>
<p>3<br>2 1<br>3 3<br>4 2<br>样例输出</p>
<p>2 1<br>3 2<br>4 2</p>
<h2 id="代码-3"><a href="#代码-3" class="headerlink" title="代码"></a>代码</h2><p>用map或set存，考察lower_bound这破玩意的使用。<br>注意在poj上用cin、cout太慢了会超时。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div></pre></td><td class="code"><pre><div class="line">#define _CRT_SECURE_NO_WARNINGS</div><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;cstdio&gt;</div><div class="line">#include &lt;map&gt;</div><div class="line">#include &lt;algorithm&gt;</div><div class="line">using namespace std;</div><div class="line">typedef long long int LL;</div><div class="line">int main()</div><div class="line">&#123;</div><div class="line">	map&lt;LL,LL&gt; mp;</div><div class="line">	int n;</div><div class="line">	cin &gt;&gt; n;</div><div class="line">	mp.insert(make_pair(1000000000,1));</div><div class="line">	while (n--)</div><div class="line">	&#123;</div><div class="line">		LL a, b;</div><div class="line">		scanf(&quot;%lld%lld&quot;, &amp;a, &amp;b);</div><div class="line">		mp.insert(make_pair(b, a));</div><div class="line">		LL t;</div><div class="line">		map&lt;LL, LL&gt;::iterator it;</div><div class="line">		map&lt;LL, LL&gt;::iterator it2;</div><div class="line">		it = mp.lower_bound(b);</div><div class="line">		it2 = mp.upper_bound(b);</div><div class="line">		if (it==mp.begin()) </div><div class="line">		&#123;</div><div class="line">			t = it2-&gt;second;</div><div class="line">		&#125;</div><div class="line">		else if (it == mp.end())</div><div class="line">		&#123;</div><div class="line">			t = it-&gt;second;</div><div class="line">		&#125;</div><div class="line">		else</div><div class="line">		&#123;</div><div class="line">			it--;</div><div class="line">			LL t1, t2;</div><div class="line">			t1 = abs(it-&gt;first - b);</div><div class="line">			t2 = abs(it2-&gt;first - b);</div><div class="line">			if (t1 &gt; t2) t = it2-&gt;second;</div><div class="line">			else t = it-&gt;second;</div><div class="line">		&#125;</div><div class="line">		printf(&quot;%lld %lld\n&quot;, a, t);</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h1 id="编程题＃6：-priority-queue练习题"><a href="#编程题＃6：-priority-queue练习题" class="headerlink" title="编程题＃6： priority queue练习题"></a>编程题＃6： priority queue练习题</h1><p>来源: POJ (Coursera声明：在POJ上完成的习题将不会计入Coursera的最后成绩。)</p>
<p>注意： 总时间限制: 2500ms 内存限制: 131072kB</p>
<p>描述</p>
<p>我们定义一个正整数a比正整数b优先的含义是：</p>
<p>*a的质因数数目（不包括自身）比b的质因数数目多；</p>
<p>*当两者质因数数目相等时，数值较大者优先级高。</p>
<p>现在给定一个容器，初始元素数目为0，之后每次往里面添加10个元素，每次添加之后，要求输出优先级最高与最低的元素，并把该两元素从容器中删除。</p>
<p>输入</p>
<p>第一行: num (添加元素次数，num &lt;= 30)</p>
<p>下面10*num行，每行一个正整数n（n &lt; 10000000).</p>
<p>输出</p>
<p>每次输入10个整数后，输出容器中优先级最高与最低的元素，两者用空格间隔。</p>
<p>样例输入</p>
<p>1<br>10 7 66 4 5 30 91 100 8 9<br>样例输出</p>
<p>66 5</p>
<h2 id="代码-4"><a href="#代码-4" class="headerlink" title="代码"></a>代码</h2><p>都1点了，实在困的不想做了。<br>优先队列只允许删除队首的元素，所以我们用两个优先队列来处理就行了。按老师教的写好myless以及mygreater比较器。（只重载&lt;号的话，两种优先级就得分别想办法处理了。。可能会比较麻烦吧，大家有别的好主意不妨给出）<br>其它没啥好说的。<br>给出的代码是网上搞来的，出处不可考。感觉写得超级棒，居然用了bitset这种神奇的东西。<br>这绝对是本题的标准答案啊，优美极了。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div></pre></td><td class="code"><pre><div class="line">#include &lt;iostream&gt;</div><div class="line">#include &lt;queue&gt;</div><div class="line">#include &lt;bitset&gt;</div><div class="line">using namespace std;</div><div class="line">bitset&lt;3200&gt; tab;</div><div class="line">int getNum(int k) &#123;</div><div class="line">	int num = 0;</div><div class="line">	for (int j = 2; j &lt; 3200 &amp;&amp; j &lt; k; j++) &#123;</div><div class="line">		if (tab[j] == 0 &amp;&amp; k % j == 0) &#123;</div><div class="line">			while (k % j == 0)</div><div class="line">				k /= j;</div><div class="line">			num++;</div><div class="line">			if (k == 1) break;</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">	if (k == 1)</div><div class="line">		return num;</div><div class="line">	else if (num == 0)</div><div class="line">		return 0;</div><div class="line">	else</div><div class="line">		return num + 1;</div><div class="line">&#125;</div><div class="line">class MyLess &#123;</div><div class="line">public:</div><div class="line">	bool operator() (pair&lt;int, int&gt; a, pair&lt;int, int&gt; b) &#123;</div><div class="line">		int num1 = a.first, num2 = a.first;</div><div class="line">		if (num1 &lt; num2)</div><div class="line">			return true;</div><div class="line">		else if (num1 == num2)</div><div class="line">			return a &lt; b;</div><div class="line">		else</div><div class="line">			return false;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">class MyGreater &#123;</div><div class="line">public:</div><div class="line">	bool operator() (pair&lt;int, int&gt; a, pair&lt;int, int&gt; b) &#123;</div><div class="line">		int num1 = a.first, num2 = a.first;</div><div class="line">		if (num1 &gt; num2)</div><div class="line">			return true;</div><div class="line">		else if (num1 == num2)</div><div class="line">			return a &gt; b;</div><div class="line">		else</div><div class="line">			return false;</div><div class="line">	&#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line">int main() &#123;</div><div class="line">	for (int i = 0; i &lt; 3200; i++)</div><div class="line">		tab[i] = 0;</div><div class="line">	tab[0] = tab[1] = 1;</div><div class="line">	for (int i = 2; i &lt; 3200; i++) &#123;</div><div class="line">		if (!tab[i])</div><div class="line">			for (int j = i + i; j &lt; 3200; j += i)</div><div class="line">				tab[j] = 1;</div><div class="line">	&#125;</div><div class="line">	int num = 0;</div><div class="line">	priority_queue&lt;int, vector&lt;pair&lt;int, int&gt; &gt;, MyLess&gt; pq1;</div><div class="line">	priority_queue&lt;int, vector&lt;pair&lt;int, int&gt; &gt;, MyGreater&gt; pq2;</div><div class="line">	cin &gt;&gt; num;</div><div class="line">	while (num--) &#123;</div><div class="line">		int tmp = 0;</div><div class="line">		for (int t = 0; t &lt; 10; t++) &#123;</div><div class="line">			cin &gt;&gt; tmp;</div><div class="line">			pq1.push(make_pair(getNum(tmp), tmp));</div><div class="line">			pq2.push(make_pair(getNum(tmp), tmp));</div><div class="line">		&#125;</div><div class="line">		cout &lt;&lt; pq1.top().second &lt;&lt; &quot; &quot; &lt;&lt; pq2.top().second &lt;&lt; endl;</div><div class="line">		pq1.pop();</div><div class="line">		pq2.pop();</div><div class="line">	&#125;</div><div class="line">	return 0;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>

      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/2016/01/24/coursera_STL2作业/">coursera_STL2作业</a></p>
        <p><span>文章作者:</span><a href="/" title="回到主页">Bingo</a></p>
        <p><span>发布时间:</span>2016-01-24, 01:19:19</p>
        <p><span>最后更新:</span>2016-01-24, 01:29:38</p>
        <p>
            <span>原始链接:</span><a class="post-url" href="/2016/01/24/coursera_STL2作业/" title="coursera_STL2作业">http://blog.acbingo.cn/2016/01/24/coursera_STL2作业/</a>
            <span class="copy-path" data-clipboard-text="原文: http://blog.acbingo.cn/2016/01/24/coursera_STL2作业/　　作者: Bingo" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" title="CC BY-NC-SA 4.0 International" target = "_blank">"署名-非商用-相同方式共享 4.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>



    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/2016/01/27/coursera_c++期末考试/">
                    coursera_c++期末考试
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2016/01/21/coursera容器适配器/">
                    coursera容器适配器_算法
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃1"><span class="toc-number">1.</span> <span class="toc-text">编程题＃1</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码"><span class="toc-number">1.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃2"><span class="toc-number">2.</span> <span class="toc-text">编程题＃2</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-1"><span class="toc-number">2.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃3：Set"><span class="toc-number">3.</span> <span class="toc-text">编程题＃3：Set</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-2"><span class="toc-number">3.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃4：-字符串操作"><span class="toc-number">4.</span> <span class="toc-text">编程题＃4： 字符串操作</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃5：-热血格斗场"><span class="toc-number">5.</span> <span class="toc-text">编程题＃5： 热血格斗场</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-3"><span class="toc-number">5.1.</span> <span class="toc-text">代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#编程题＃6：-priority-queue练习题"><span class="toc-number">6.</span> <span class="toc-text">编程题＃6： priority queue练习题</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#代码-4"><span class="toc-number">6.1.</span> <span class="toc-text">代码</span></a></li></ol></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"false"];
    </script>



    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"coursera_STL2作业　| Bingo's Blog　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    
      <div class="duoshuo" id="comments">
    <div id="comment-box" ></div>
    <div class="ds-thread" id="ds-thread" data-thread-key="2016/01/24/coursera_STL2作业/" data-title="coursera_STL2作业" data-url="http://blog.acbingo.cn/2016/01/24/coursera_STL2作业/"></div>
    <script>
        var duoshuoQuery = {short_name:"acbingo"};
        var loadComment = function(){
            var d = document, s = d.createElement('script');
            s.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            s.async = true; s.charset = 'UTF-8';
            (d.head || d.body).appendChild(s);
        }

        
    </script>
    
    <script> loadComment(); </script>

</div>
    




    <div class="scroll" id="post-nav-button">
        
            <a href="/2016/01/27/coursera_c++期末考试/" title="上一篇: coursera_c++期末考试">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2016/01/21/coursera容器适配器/" title="下一篇: coursera容器适配器_算法">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2016/08/07/c++初始化列表/">c++初始化列表</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/05/一步一步学习红黑树-2/">一步一步学习红黑树-2</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/04/一步一步学习红黑树/">一步一步学习红黑树-1</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/回文解码/">回文解码</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/C++中虚析构函数的作用/">C++中虚析构函数的作用</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/const/">const</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/08/03/const与常成员函数/">const与常成员函数</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/31/虚拟继承/">虚拟继承</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/31/函数指针/">函数指针</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/记事本/">记事本</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/StarFiles/">StarFiles</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/酒店管理系统/">酒店管理系统</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/28/飞机大战/">飞机大战</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/27/仿函数/">仿函数/函数对象</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/27/二叉树中和为某一值的路径/">二叉树中和为某一值的路径</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/递归实现反转列表/">递归实现反转链表</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/快速幂/">快速幂</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/bitset的用法/">bitset的用法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/26/二分查找、归并排序和快速排序/">二分查找、归并排序和快速排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/25/重建二叉树/">重建二叉树</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/25/leetcode_5/">LeetCode_5:Longest Palindromic Substring</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_4/">LeetCode_4:Median of Two Sorted Arrays</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_3/">LeetCode_3:Longest Substring Without Repeating Characters</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_2/">LeetCode_2:Add Two Numbers</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/07/24/leetcode_1_Two Sum/">LeetCode_1:Two Sum</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/06/07/Bingo's_ShadowSocks使用说明/">Bingo's_Shadowsocks</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/03/如何优雅的开启wifi热点/">如何优雅的开启wifi热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/02/如何优雅的连接指定wifi热点/">如何优雅的连接指定wifi热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/02/对AndroidWifi状态广播的研究/">对AndroidWifi状态广播的研究</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/01/coursera数据结构_字符串_课后作业/">coursera数据结构_字符串_课后作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/05/01/简单几步在Android_Studio上实现二维码的扫描/">简单几步在Android_Studio上实现二维码的生成与扫描</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/25/coursera_算法课后习题/">coursera_算法课后习题</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/25/coursera_计算机组成学习笔记/">coursera_计算机组成学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/20/cocos2dx-飞机大战/">cocos2dx-飞机大战</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/14/android_ping不通电脑/">android_ping不通电脑</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/14/android创建与连接热点/">android创建与连接热点</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/01/coursera_算法_递归/">coursera_算法_递归</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/30/coursera_操作系统学习笔记/">coursera_操作系统学习笔记_计算机操作系统概述</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/29/编译原理_中科大公开课_第一单元编译器介绍作业/">编译原理_中科大公开课_第一单元编译器介绍作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/25/关于Inflater与findViewById()的思考/">关于Inflater与findViewById()的思考</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/11/coursera_魔兽世界终结版/">coursera_魔兽世界终结版</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/05/coursera_算法作业_枚举/">coursera_算法作业_枚举</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/27/coursera_c++高级主体和c++11新特性/">coursera_c++高级主体和c++11新特性</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/27/coursera_c++期末考试/">coursera_c++期末考试</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/24/coursera_STL2作业/">coursera_STL2作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/21/coursera容器适配器/">coursera容器适配器_算法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/21/coursera标准模版库STL2/">coursera标准模版库STL2</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/20/coursera编程作业-STL1/">coursera编程作业-STL1</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/20/coursera疑问/">coursera疑问</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/coursera学习笔记-函数对象/">coursera学习笔记-函数对象</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/01/19/coursera学习笔记-顺序容器Vector/">coursera学习笔记-顺序容器Vector、List和Deque</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/05/算法学习笔记-14-最长公共子序列/">算法学习笔记-14-最长公共子序列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/03/算法学习笔记-13-矩阵连乘问题/">算法学习笔记-13-矩阵连乘问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-12-循环赛日程表/">算法学习笔记-12-循环赛日程表</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-11-最接近点对问题/">算法学习笔记-11-最接近点对问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/12/01/算法学习笔记-10-线性时间选择/">算法学习笔记-10-线性时间选择</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/27/算法学习笔记-9-快速排序/">算法学习笔记-9-快速排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/26/算法学习笔记-8-合并排序/">算法学习笔记-8-归并排序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/24/算法学习笔记-7-棋盘覆盖问题/">算法学习笔记-7-棋盘覆盖问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/22/算法学习笔记-6-Strassen矩阵乘法/">算法学习笔记-6-Strassen矩阵乘法</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/21/算法学习笔记-5-Hanoi塔问题/">算法学习笔记-5-Hanoi塔问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/20/算法学习笔记-4-整数划分问题/">算法学习笔记-4-整数划分问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/19/算法学习笔记-3-排列问题/">算法学习笔记-3-排列问题</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/18/算法学习笔记-2-递归的概念/">算法学习笔记-2-递归的概念</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/coursera_标准模板库STL/">coursera_标准模板库STL</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/算法学习笔记-0-序/">算法学习笔记-0-序</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/17/算法学习笔记-1-NP完全性理论/">算法学习笔记-1-NP完全性理论</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/14/文件操作和模板_编程作业/">文件操作和模板_编程作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/11/ubuntu下安装最新的nodejs(v4.2.2)/">ubuntu下安装最新的nodejs(v4.2.2)</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/11/ubuntu14.04的环境变量/">ubuntu14.04的环境变量</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/11/01/coursera学习笔记_文件操作和模板/">coursera学习笔记_文件操作和模板</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/31/coursera学习笔记_多态和虚函数/">coursera学习笔记_多态和虚函数</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/28/Coursera_程序设计与晋级_继承与派生_编程作业/">Coursera_程序设计与晋级_继承与派生_编程作业</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/22/科大OJ-数据结构-DNA序列/">科大OJ-数据结构-DNA序列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/20/科大OJ-数据结构-求表达式串的后缀表达式和值/">科大OJ-数据结构-求表达式串的后缀表达式和值</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/10/01/科大OJ-数据结构-击鼓传花/">科大OJ-数据结构-击鼓传花</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/30/科大OJ-数据结构-求集合的交并补集/">科大OJ-数据结构-求集合的交并补集</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/27/hexo无法本地访问/">hexo无法本地访问</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/26/继承与派生/">coursera学习笔记_继承与派生</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/26/大数类模板/">大数类模板</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/15/vimium学习笔记/">vimium学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/04/程序员矩阵/">程序员矩阵</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/03/coursera学习笔记_运算符重载/">coursera学习笔记_运算符重载</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/09/01/写hexo博客、markdown文章时图床的挑选/">写hexo博客、markdown文章时图床的挑选</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/31/coursera学习笔记-c++程序设计/">coursera学习笔记-c++程序设计</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/29/Linux下C语言应用编程学习笔记/">Linux下C语言应用编程学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/28/linux学习笔记2/">linux学习笔记2</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/Bingo's exVim/">Bingo的VIM</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/linux下去掉^M的方法/">linux下去掉^M的方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/27/vim的持久撤销功能/">vim的持久撤销功能</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/25/linux学习笔记/">linux学习笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-7-hdu1698/">线段树学习笔记-7-hdu1698</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-6-区间更新/">线段树学习笔记-6-区间更新</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/Coursera_程序设计与算法_C程序设计进阶/">Coursera_程序设计与算法_C程序设计进阶</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/18/线段树学习笔记-5-hdu2795/">线段树学习笔记-5-hdu2795</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/线段树学习笔记-4-hdu1394/">线段树学习笔记-4-hdu1394</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/求逆序对的个数/">求逆序对的个数</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/14/线段树学习笔记-3-hdu1754/">线段树学习笔记-3-hdu1754</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/13/线段树学习笔记-2-hdu1166/">线段树学习笔记-2-hdu1166</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/13/线段树学习笔记/">线段树学习笔记-1-入门</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/11/Coursera_程序设计与算法_计算导论与C语言基础_期末编程测试/">Coursera_程序设计与算法_计算导论与C语言基础_期末编程测试</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/Coursera_程序设计与算法_C程序设计进阶_C程序中的函数/">Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习/">Coursera_程序设计与算法_计算导论与C语言基础_数组应用练习</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/10/hdu4821 String/">hdu4821 String</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/09/Rolling Hash(Rabin-Karp算法)匹配字符串/">Rolling Hash(Rabin-Karp算法)匹配字符串</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/09/设置vim的默认工作路径/">设置vim的默认工作路径</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/08/滑动窗口的单调队列/">滑动窗口的单调队列</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/08/08/ssh -T git@github.com出现Permission denied (publickey)/">ssh -T git@github.com出现Permission denied (publickey)</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/05/29/UVa10791-Minimum-Sum-LCM/">UVa10791-Minimum Sum LCM</a></li><li class="post-list-item"><a class="post-list-link" href="/2015/05/29/uva100/">uva100</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2014-2016 Bingo
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>